package com.xiaoqi.store.controller;

import com.xiaoqi.store.entity.JsonResult;
import com.xiaoqi.store.entity.OrderEntity;
import com.xiaoqi.store.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Author Rookie Coder
 * @Description 订单控制层
 * @Date
 **/
@RestController
@RequestMapping("orders")
public class OrderController extends BaseController{

    @Autowired
    private OrderService orderService;
    /*
    * @Author xiaoqi
    * @Description  创建订单
    * @return
    **/
    @PostMapping("/create")
    public JsonResult createUserOrder(Integer aid,Integer[] cids,HttpSession session){
        Integer uidFromSession = getUidFromSession(session);
        String usernameFromSession = getUsernameFromSession(session);
        OrderEntity orderEntity = orderService.insertAllOrder(aid, cids, uidFromSession, usernameFromSession);
        return  new JsonResult(OK,orderEntity);
    }

}
